<?php
/**
 *@Status: PASS
 *@Author: IAN-QWL
 *@Function: Return-PDO
 */
!defined('IAN') && exit('Access Denied');
  
final class DB extends PDO
{
	private $pdo;
	public function __construct(&$link)
	{	
		$dsn = "$link[dbms]:host=$link[dbhost];dbname=$link[dbname];charset=$link[dbcharset]";
		if($link['dbkeep'])
		{
			/* long-link */
			$link['dbkeep'] = array(PDO::ATTR_PERSISTENT => true);
			try 
			{
				$this->pdo = new PDO($dsn,$link['dbuser'],$link['dbpwd'],$link['dbkeep']);
			} 
			catch (PDOException $e) 
			{	
				exit('Connection failed: '.$e->getMessage());
			}
		}
		else
		{
			try 
			{		
				$this->pdo = new PDO($dsn,$link['dbuser'],$link['dbpwd']);
			} 
			catch (PDOException $e) 
			{	
				exit('Connection failed: '.$e->getMessage());
			}
		}
	}
	public function getPDO()
	{
		return $this->pdo;	
	}
	public function __destruct()
	{
		/* destruct function */
	}
}

/* link-parameters */
$db = new DB($db_link);
$pdo = $db->getPDO();
unset($db,$db_link);

?>